
'unit tests for TEntityTemplate

Type TemplateTest Extends TTest

	Field t:TTemplates
	
	Method Before() {before}
		t = New TTemplates
	End Method
	
	Method After() {after}
		t = Null
	End Method
	
	Method Constructor() {test}
		assertNotNull(t, "could not create templates manager")
	End Method
	
	
	Method LoadTest() {test}
		Local s:TStream = OpenStream("implementationtests/templates.txt")
		If s Then t.Read(s)
		s.Close()
		
		'there should now be a template added at index 0		
		'and at index 2
		assertNotNull(t.Get(0), "no template 0")
		assertNotNull(t.Get(2), "no template 2")
	End Method
	
	
	Method WriteTest() {test}
		Local s:TStream = OpenStream("implementationtests/templates.txt")
		If s Then t.Read(s)
		s.Close()
	
		s = WriteStream("implementationtests/templates_write.txt")
		If s Then t.Write(s)
		s.Close()
		
		assertEqualsI(1, FileType("implementationtests/templates_write.txt"), "not saved!")
	End Method
	
	
	Method SettingsTest() {test}
		Local s:TStream = OpenStream("implementationtests/templates.txt")
		If s Then t.Read(s)
		s.Close()
		
		Local template:TEntityTemplate = t.Get(0)
		Local testString:String
		testString = template.GetComponentSetting("script")
		assertEquals ("script.lua", testString, "script string not correct!")
		
		testString = template.getcomponentsetting("transform")
		assertEquals("1.0,1.0,0.0", testString, "transform string not correct!")
	End Method

	
	Method ImageTest() {test}
		Local s:TStream = OpenStream("implementationtests/templates.txt")
		If s Then t.Read(s)
		s.Close()
		
		assertNotNull(TResources.GetImage("playership"), "image playership not loaded")
	End Method	
	
End Type
